<script setup>
import { useMarketingApi } from '/@/api/marketing';
import { useOptions } from '/@/stores/options';
const optionStore = useOptions();
const { getPositionList } = useMarketingApi();
const props = defineProps({
	modelValue: {
		type: Number,
	},
	dotDisable: {
		type: Boolean,
		default: false,
	},
});
const emit = defineEmits(['update:modelValue', 'select']);
const selected = computed({
	get: () => props.modelValue,
	set: () => {},
});
const options = ref([]);
const loading = ref(false);
async function init() {
	try {
		loading.value = true;
		let res = await getPositionList({
			pageSize: 99,
			current: 1,
		});
		loading.value = false;
		if (res.code !== 200) return;
		options.value = res.data.data;
		// emit('update:modelValue', res.data.data[0].id);
		optionStore.setPositionList(res.data.data);
	} catch (error) {
		loading.value = false;
	}
}
onMounted(init);
function change(val) {
	emit('update:modelValue', val);
	emit('select', val);
}
</script>
<template>
	<el-select v-model="selected" :loading="loading" clearable @change="change" v-bind="$attrs">
		<el-option
			v-for="item in options"
			:label="item.positionName"
			:value="item.id"
			:disabled="dotDisable && item.type === 5"
			:key="item.id"
		></el-option>
	</el-select>
</template>
